﻿using System;
using System.ComponentModel;
using System.Threading;
using Silverlight.Training.Client.Common.ServiceReference.Contracts;
using Silverlight.Training.Client.Common.ServiceReference.EventArgs;
using Silverlight.Training.Client.Common.ServiceReference.Feedbacks;
using Silverlight.Training.Client.Common.ServiceReference.Interfaces;

namespace Silverlight.Training.Client.Common.ServiceReference.Operations
{
    public partial class EMServiceClient
    {
        #region GetEmployeeCollection

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Employee>> GetEmployeeCollectionCompleted;
        
        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        IAsyncResult IEMService.BeginGetEmployeeCollection(AsyncCallback callback, object asyncState)
        {
            return base.Channel.BeginGetEmployeeCollection(callback, asyncState);
        }

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        CollectionFeedback<Employee> IEMService.EndGetEmployeeCollection(IAsyncResult result)
        {
            return base.Channel.EndGetEmployeeCollection(result);
        }

        private IAsyncResult OnBeginGetEmployeeCollection(object[] inValues, AsyncCallback callback, object asyncState)
        {
            return ((IEMService)(this)).BeginGetEmployeeCollection(callback, asyncState);
        }

        private object[] OnEndGetEmployeeCollection(IAsyncResult result)
        {
            CollectionFeedback<Employee> retVal = ((IEMService)(this)).EndGetEmployeeCollection(result);
            return new object[] {
                retVal};
        }

        private void OnGetEmployeeCollectionCompleted(object state)
        {
            if ((this.GetEmployeeCollectionCompleted != null))
            {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                this.GetEmployeeCollectionCompleted(this, new CollectionFeedbackCompletedEventArgs<Employee>(e.Results, e.Error, e.Cancelled, e.UserState));
            }
        }

        public void GetEmployeeCollectionAsync()
        {
            this.GetEmployeeCollectionAsync(null);
        }

        public void GetEmployeeCollectionAsync(object userState)
        {
            if ((this.onBeginGetEmployeeCollectionDelegate == null))
            {
                this.onBeginGetEmployeeCollectionDelegate = new BeginOperationDelegate(this.OnBeginGetEmployeeCollection);
            }
            if ((this.onEndGetEmployeeCollectionDelegate == null))
            {
                this.onEndGetEmployeeCollectionDelegate = new EndOperationDelegate(this.OnEndGetEmployeeCollection);
            }
            if ((this.onGetEmployeeCollectionCompletedDelegate == null))
            {
                this.onGetEmployeeCollectionCompletedDelegate = new SendOrPostCallback(this.OnGetEmployeeCollectionCompleted);
            }
            base.InvokeAsync(this.onBeginGetEmployeeCollectionDelegate, null, this.onEndGetEmployeeCollectionDelegate, this.onGetEmployeeCollectionCompletedDelegate, userState);
        }

        private BeginOperationDelegate onBeginGetEmployeeCollectionDelegate;

        private EndOperationDelegate onEndGetEmployeeCollectionDelegate;

        private SendOrPostCallback onGetEmployeeCollectionCompletedDelegate;

        private partial class EMServiceClientChannel
        {
            public IAsyncResult BeginGetEmployeeCollection(AsyncCallback callback, object asyncState)
            {
                object[] _args = new object[0];
                IAsyncResult _result = base.BeginInvoke("GetEmployeeCollection", _args, callback, asyncState);
                return _result;
            }

            public CollectionFeedback<Employee> EndGetEmployeeCollection(IAsyncResult result)
            {
                object[] _args = new object[0];
                CollectionFeedback<Employee> _result = ((CollectionFeedback<Employee>)(base.EndInvoke("GetEmployeeCollection", _args, result)));
                return _result;
            }
        }

        #endregion

        #region GetSingleEmployee

        public event EventHandler<SingleFeedbackCompletedEventArgs<Employee>> GetSingleEmployeeCompleted;

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        IAsyncResult IEMService.BeginGetSingleEmployee(int employeeID, AsyncCallback callback, object asyncState)
        {
            return base.Channel.BeginGetSingleEmployee(employeeID, callback, asyncState);
        }

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        SingleFeedback<Employee> IEMService.EndGetSingleEmployee(IAsyncResult result)
        {
            return base.Channel.EndGetSingleEmployee(result);
        }

        private IAsyncResult OnBeginGetSingleEmployee(object[] inValues, AsyncCallback callback, object asyncState)
        {
            int employeeID = ((int)(inValues[0]));
            return ((IEMService)(this)).BeginGetSingleEmployee(employeeID, callback, asyncState);
        }

        private object[] OnEndGetSingleEmployee(IAsyncResult result)
        {
            SingleFeedback<Employee> retVal = ((IEMService)(this)).EndGetSingleEmployee(result);
            return new object[] {
                retVal};
        }

        private void OnGetSingleEmployeeCompleted(object state)
        {
            if ((this.GetSingleEmployeeCompleted != null))
            {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                this.GetSingleEmployeeCompleted(this, new SingleFeedbackCompletedEventArgs<Employee>(e.Results, e.Error, e.Cancelled, e.UserState));
            }
        }

        public void GetSingleEmployeeAsync(int employeeID)
        {
            this.GetSingleEmployeeAsync(employeeID, null);
        }

        public void GetSingleEmployeeAsync(int employeeID, object userState)
        {
            if ((this.onBeginGetSingleEmployeeDelegate == null))
            {
                this.onBeginGetSingleEmployeeDelegate = new BeginOperationDelegate(this.OnBeginGetSingleEmployee);
            }
            if ((this.onEndGetSingleEmployeeDelegate == null))
            {
                this.onEndGetSingleEmployeeDelegate = new EndOperationDelegate(this.OnEndGetSingleEmployee);
            }
            if ((this.onGetSingleEmployeeCompletedDelegate == null))
            {
                this.onGetSingleEmployeeCompletedDelegate = new SendOrPostCallback(this.OnGetSingleEmployeeCompleted);
            }
            base.InvokeAsync(this.onBeginGetSingleEmployeeDelegate, new object[] {
                    employeeID}, this.onEndGetSingleEmployeeDelegate, this.onGetSingleEmployeeCompletedDelegate, userState);
        }

        private BeginOperationDelegate onBeginGetSingleEmployeeDelegate;

        private EndOperationDelegate onEndGetSingleEmployeeDelegate;

        private SendOrPostCallback onGetSingleEmployeeCompletedDelegate;

        private partial class EMServiceClientChannel
        {
            public IAsyncResult BeginGetSingleEmployee(int employeeID, AsyncCallback callback, object asyncState)
            {
                object[] _args = new object[1];
                _args[0] = employeeID;
                IAsyncResult _result = base.BeginInvoke("GetSingleEmployee", _args, callback, asyncState);
                return _result;
            }

            public SingleFeedback<Employee> EndGetSingleEmployee(IAsyncResult result)
            {
                object[] _args = new object[0];
                SingleFeedback<Employee> _result = ((SingleFeedback<Employee>)(base.EndInvoke("GetSingleEmployee", _args, result)));
                return _result;
            }
        }

        #endregion
    }
}
